const { UUIDV4, UUID, STRING, INTEGER, TINYINT, DOUBLE, Model } = require('sequelize');
const db = require('../../helpers/db');

class Cart extends Model {}

Cart.init(
    {
        id: {
            type: UUID,
            defaultValue: UUIDV4,
            primaryKey: true,
            comment: '购物车 ID'
        },
        no: {
            type: STRING(24),
            comment: '购物车编号'
        },
        goods: {
            type: UUID,
            unique: true,
            comment: '外键，商品ID'
        },
        user: {
            type: UUID,
            unique: true,
            comment: '外键，用户ID'
        },
        goodsSKU: {
            type: UUID,
            unique: true,
            comment: '外键，商品SKU ID'
        },
        count: {
            type: INTEGER,
            comment: '数量',
            defaultValue: 1
        },
        joinPrice: {
            type: DOUBLE,
            comment: '订单加入时价格',
            defaultValue: 0
        }
    },
    {
        tableName: 'cart',
        underscored: true,
        sequelize: db
    }
);

module.exports = Cart;
